package com.xinjiang.electricpower.timer;

import lombok.extern.slf4j.Slf4j;
import org.springframework.scheduling.annotation.Scheduled;
import org.springframework.stereotype.Component;

import java.io.InputStream;

/**
 * @Author D_TZ
 * @Date 2023/3/416:03
 * @ClassName GongZhiOrderTask
 * @Desription 供指数据同步与
 **/
@Component
@Slf4j
public class GongZhiOrderTask {


    /**
     * 执行供指数据
     *
     * @return
     */
//    @Async
    @Scheduled(cron = "0 30 1 ? * *")  //每天01:30
    public void gzCjxqWorkOrderKjb() {
        try {
            log.info("同步供服数据");
            InputStream in = this.getClass().getClassLoader().getResourceAsStream("gongfu/gongfu_work_order.ktr");
            //执行对应ktr 文件转换
            KettleQuartz.runKettleTransfer(null, KettleQuartz.CJ_BH, in);
            log.info("同步供服数据");
            //Thread.sleep(500);
        } catch (Exception e) {
            log.error("拉取{}工单数据异常 {}", e);
        }
    }

    @Scheduled(cron = "0 30 4 ? * *")  //每天04:30
    public void gzSbqxWorkOrderKjb() {
        try {
            log.info("同步供服设备抢修定时任务开启~~~~");
            InputStream in = this.getClass().getClassLoader().getResourceAsStream("gongfu/gongfu_qiang_xiu.ktr");
            //执行对应ktr 文件转换
            KettleQuartz.runKettleTransfer(null, KettleQuartz.CJ_BH, in);
            log.info("同步供服设备抢修定时任务结束~~~~");
            //Thread.sleep(500);
        } catch (Exception e) {
            log.error("拉取{}工单数据异常 {}", e);
        }
    }


    /**
     * 执行供指配置类
     *
     * @return
     */
//    @Async
    @Scheduled(cron = "0 30 5 ? * *")  //每天05:30
    public void gzConfigCjxqWorkOrderKjb() {
        try {
            log.info("同步闭供服配置时任务开启~~~~");
            InputStream in = this.getClass().getClassLoader().getResourceAsStream("gongfu/gongfu_work_order_config.ktr");
            //执行对应ktr 文件转换
            KettleQuartz.runKettleTransfer(null, KettleQuartz.CJ_BH, in);
            log.info("同步闭供服配置定时任务结束~~~~");
            //Thread.sleep(500);
        } catch (Exception e) {
            log.error("拉取{}工单数据异常 {}", e);
        }
    }

}
